package jwdt.xadmin.custom.service.impl;

import java.util.List;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.custom.bean.TCarsq;
import jwdt.xadmin.custom.service.CarsqManageService;
import jwdt.xadmin.system.bean.TUser;

import com.ezerg.db.Jdb;
import com.ezerg.web.Form;
import com.ezerg.web.Module;

public class CarsqManageServiceImpl implements CarsqManageService {

	private BaseDao<TCarsq> baseDao;
	
	public void setBaseDao(BaseDao<TCarsq> baseDao) {
		this.baseDao = baseDao;
	}
	
	
	@Override
	public String carsqAddact(TCarsq obj,TUser userInfo) throws Exception{
		
		obj.setSqr(userInfo.getUserid());
		obj.setStatus(100);
		return baseDao.doAddObj(obj);
	}

	@Override
	public TCarsq carsqEdit(int id) throws Exception{
		return baseDao.doLoadObj(TCarsq.class,id);
		
	}

	@Override
	public String carsqEditact(TCarsq obj,int id) throws Exception{
		return baseDao.doUpdateObj(TCarsq.class,id,obj);
	}

	@Override
	public String carsqDel(int id) throws Exception{
		return baseDao.doDelObj(TCarsq.class,id);
	}

	@Override
	public List carsqCheck(String status) throws Exception{
		
		return Jdb.get().query("SELECT * FROM t_car_sq a LEFT JOIN (SELECT fullname,UserId FROM t_user ) b ON a.sqr=b.UserId  where status="+status+"");
	}

	@Override
	public List carSq(String sql) throws Exception{
		
		return Jdb.get().query("SELECT * FROM t_car_sq"+sql);
	}
	
	@Override
	public String carsqSpb(Form f, Module m,String id) throws Exception{
		
		TCarsq obj = (TCarsq) Jdb.get().get(TCarsq.class, id);
		obj.setStatus(102);
		obj = (TCarsq) f.copy2Obj(obj);
		return baseDao.doUpdateObj(TCarsq.class,id,obj);
	}
	
	@Override
	public String carsqSpt(Form f, Module m,String id) throws Exception{
		
		TCarsq obj = (TCarsq) Jdb.get().get(TCarsq.class, id);
		obj.setStatus(101);
		obj = (TCarsq) f.copy2Obj(obj);
		return baseDao.doUpdateObj(TCarsq.class,id,obj);
	}
	
	@Override
	public List carsqXz(Form f, Module m) throws Exception{
		
		return Jdb.get().query("SELECT t_dep.id AS bmid,t_rsxx.id AS userid,t_rsxx.fullname AS username,t_dep.name FROM t_rsxx LEFT JOIN t_dep ON t_rsxx.depid=t_dep.id ");
	}
	
	@Override
	public List carsqXzbm() throws Exception{
		
		return Jdb.get().query("SELECT * FROM t_dep");
	}
	
	@Override
	public List cpxxSq() throws Exception{
		
		return Jdb.get().query("SELECT cph FROM t_car where status=0");
	}
}
